namespace CaltechSoft.Service.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class WorkOrder2 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Equipment", "WorkOrder_WorkOrderId", "dbo.WorkOrders");
            DropIndex("dbo.Equipment", new[] { "WorkOrder_WorkOrderId" });
            CreateTable(
                "dbo.WorkOrderDetails",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        EquipmentId = c.Int(nullable: false),
                        WorkOrderId = c.Int(nullable: false),
                        CreatedBy = c.Int(nullable: false),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Equipment", t => t.EquipmentId, cascadeDelete: true)
                .ForeignKey("dbo.WorkOrders", t => t.WorkOrderId, cascadeDelete: true)
                .Index(t => t.EquipmentId)
                .Index(t => t.WorkOrderId);
            
            DropColumn("dbo.Equipment", "WorkOrder_WorkOrderId");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Equipment", "WorkOrder_WorkOrderId", c => c.Int());
            DropForeignKey("dbo.WorkOrderDetails", "WorkOrderId", "dbo.WorkOrders");
            DropForeignKey("dbo.WorkOrderDetails", "EquipmentId", "dbo.Equipment");
            DropIndex("dbo.WorkOrderDetails", new[] { "WorkOrderId" });
            DropIndex("dbo.WorkOrderDetails", new[] { "EquipmentId" });
            DropTable("dbo.WorkOrderDetails");
            CreateIndex("dbo.Equipment", "WorkOrder_WorkOrderId");
            AddForeignKey("dbo.Equipment", "WorkOrder_WorkOrderId", "dbo.WorkOrders", "WorkOrderId");
        }
    }
}
